package com.etone.smartAudit.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.etone.smartAudit.domain.CertificateGroupAdmin;
import com.etone.smartAudit.mapper.CertificateGroupAdminMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 存证单与用户关联表  服务实现类
 * </p>
 *
 * @author jiayen
 * @since 2021-06-08
 */
@Service
public class CertificateGroupAdminService extends ServiceImpl<CertificateGroupAdminMapper, CertificateGroupAdmin> {

    /***
     * 保存群组与群的关联关系
     * @param adminId
     * @param groupId
     */
    public void saveOrupdateAdmin(Integer adminId, Integer groupId) {
        if (adminId != null && groupId != null) {
            LambdaQueryWrapper<CertificateGroupAdmin> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(CertificateGroupAdmin::getAdminId, adminId)
                    .eq(CertificateGroupAdmin::getGroupId, groupId);
            List<CertificateGroupAdmin> list = this.list(queryWrapper);
            if (CollectionUtil.isEmpty(list)) {
                CertificateGroupAdmin admin = new CertificateGroupAdmin();
                admin.setAdminId(adminId);
                admin.setGroupId(groupId);
                admin.setCreateTime(LocalDateTime.now());
                this.save(admin);
            }
        }

    }
}
